{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn\n",
    "import torch.nn.functional as F\n",
    "from STN import SpatialTransformer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. 构造一个 STN 实例\n",
    "stn = SpatialTransformer(in_channels=3)       # 假设输入图像是 RGB 三通道"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. 随机制造一个输入 (batch_size=4, 通道=3, 高=256, 宽=256)\n",
    "x = torch.randn(4, 3, 256, 256)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入形状 : torch.Size([4, 3, 256, 256])\n",
      "输出形状 : torch.Size([4, 3, 256, 256])\n"
     ]
    }
   ],
   "source": [
    "# 3. 前向\n",
    "with torch.no_grad():\n",
    "    y = stn(x)\n",
    "\n",
    "# 4. 打印形状，确认和输入一致\n",
    "print(\"输入形状 :\", x.shape)   # 期望 torch.Size([4, 3, 256, 256])\n",
    "print(\"输出形状 :\", y.shape)   # 期望 torch.Size([4, 3, 256, 256])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "science39",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
